#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<errno.h>
#include "ourhdr.h"
 

int main(int argc,char **argv)
{
    char          buf1[]="abcdefghijkl";
    char          buf2[]="ABCDEFG";
    int           fd=-1;
    off_t         offset=0;

    if((fd=creat("file.hole",FILE_MODE)) < 0)//创建一个文件
    {
        printf("creat failure: %s\n",strerror(errno));
    }

    if(write(fd,buf1,sizeof(buf1)) < 0)//向该文件中写buf1
    {
        printf("buf1 is writed  failure: %s\n",strerror(errno));
    }

    if((offset=lseek(fd,40,SEEK_SET)) == -1)//文件偏移40
    {
        printf("lseek failure: %s\n",strerror(errno));
    }
    else 
    {
        printf("Current lseek: %ld\n",offset);
    }

    if(write(fd,buf2,sizeof(buf2)) < 0)//偏移之后再写入buf2
    {
        printf("buf2 is writed failure: %s\n",strerror(errno));
    }

    return 0;

    
}
